//
//  BWFNavigationController.swift
//  网易新闻项目
//
//  Created by 薄文飞 on 16/3/3.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class BWFNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.whiteColor()
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        var title = "返回"
        if childViewControllers.count > 0 {
            
            if childViewControllers.count == 1 {
                
                title = childViewControllers.first?.title ?? "返回"
                
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", titel: title, target: self, action: "back")
            
            viewController.navigationItem.title = "第\(childViewControllers.count)级控制器"
            viewController.hidesBottomBarWhenPushed = true
            
        }
        
        super.pushViewController(viewController, animated:true)
        
    }
    
    func back() {
        
        popViewControllerAnimated(true)
        
    }
}
